<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/index.css" />
		<link rel="stylesheet" type="text/css" href="../../css/mine.css" />
		<link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_546019_o8qxm6fupb0ggb9.css" />
		<title>修改/删除物料</title>
		<script src="../../js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/baseConfig.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<!--<div id="header">
			<div class="header-title" style="position: fixed;top: 0;">
				<img src="../../img/left.png" class="left" />
				<span>修改/删除物料</span>
			</div>
		</div>-->
		<div class="mine-content" style="margin-bottom: 0;margin-top: 0;">
			<!--过磅列表 -->
			<div class="name  select-type">
				<span>订单编号</span>
				<!--<i class="iconfont icon-sanjiaodown vebdorIcon"></i>-->
				<input type="text" class="vebdor-type" disabled="disabled" />
				<ul class="name_ul person_type">

				</ul>
			</div>
			<div class=" name select-type">
				<span>物料名称</span>
				<!--<i class="iconfont icon-sanjiaodown documentIcon"></i>-->
				<input type="text" class="document-type" disabled="disabled" />

			</div>
			<div class="name" style="border-bottom: none;">
				<span>装车重量</span>
				<input type="number" name="number" pattern="[0-9]*" class="company-phone" /> 吨
			</div>
			<div class="demos-content-padded" style="margin-top: 1.5rem;">
				<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_warn default" style="float: left;">删除</a>
				<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary confirm" style="float: right;margin-top: 0;background: #28c81e;">确定</a>
				<!--<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary delete" style="float: right;margin-top: 0;background: #f65555;margin-top: 20px;">删除</a>-->
			</div>
		</div>

	</body>
	<script type="text/javascript">
		$(document).ready(function() {
			baseConfig.historyBack()

			function GetQueryString(name) { //页面取值方法
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) return decodeURI(r[2]);
				return null;
			}
			var voId = GetQueryString("voId") //物料id
			var id = GetQueryString("id")
			var orderNo = GetQueryString("orderNo") //订单号
			var carNo = GetQueryString("carNo"); //车牌号
			var driver = GetQueryString("driver"); //司机姓名
			var phone = GetQueryString("phone"); //司机电话
			var uploadTime = GetQueryString("uploadTime"); //装车时间
			var idCard = GetQueryString("idCard"); //司机身份证
			var planTime = GetQueryString("planTime"); //预计到达时间
			var weight = GetQueryString("weight"); //装车物料重量
			var goodsNo = GetQueryString("goodsNo")  //默认的物料id
//			$(".company-phone").val(weight)
			$.ajax({
				type: "get",
				url: baseConfig.localHttp + "weChatApi/fgclient/getGoodsDetail",
				async: false,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				data: {
					voId: voId
				},
				success: function(data) {
					console.log(data)
					if(data.code == 100) {
						$(".vebdor-type").val(data.content.orderNo);
						$(".document-type").val(data.content.goodsName);
						$(".company-phone").val(data.content.goodsWeight)
//						$.ajax({
//							type: "get",
//							url: baseConfig.localHttp + "weChatApi/fgclient/getGoodsNameList",
//							async: false,
//							headers: {
//								'Content-Type': 'application/x-www-form-urlencoded'
//							},
//							data: {
//								orderNo: orderNo
//							},
//							success: function(data) {
//								console.log(data)
//								var Data = data.content
//								var temp = [];
//								for(var i=0;i<Data.length;i++){
//									temp.push(Data[i].goodsName)
//								}
//								if(data.code == 100) {
//									$(".documentIcon").picker({
//										title: "请选择物料名称",
//										cols: [{
//											textAlign: 'center',
//											values: temp
//										}],
//										onClose: function(e) {
//											var index = e.cols[0].activeIndex					
//											goodsNo = Data[index].goodsNo
////											sessionStorage.setItem("goodsNo",goodsNo)
//											$(".document-type").val(e.value)
//										}
//									});
//
//								} else {
//									$.toptip(data.content, 1200, 'error');
//								}
//							},
//							error:function(){
//								$.toptip(data.content, 1200, 'error');
//							}
//						})

					} else {

					}
				}
			})


			//点击删除物料
			$('.default').on("click", function() {
				$.confirm("确定删除该物料？", function() {
				  //点击确认后的回调函数
					  $.ajax({
						type: "get",
						url: baseConfig.localHttp + "weChatApi/fgclient/delTranGoods",
						async: false,
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
						data: {				
							voId:voId,
							orderNo:orderNo,
							carNo:carNo,
							id:id,
							goodsWeight:weight
						},
						success: function(data) {
							console.log(data)
							if(data.code == 100) {						
								window.location.replace(document.referrer)
							} else {
								$.toptip(data.content, 1200, 'error');
							}
						}
					})
				  }, function() {
				  //点击取消后的回调函数
				 });
			})
			
			//点击确认，判断数据是否填写完整，然后跳转回上一个页面
				$('.confirm').on("click", function() {
				var orderNumber = $(".vebdor-type").val();
				var materialName = $(".document-type").val();
				var weight = $(".company-phone").val();
				$.ajax({
					type: "get",
					url: baseConfig.localHttp + "weChatApi/fgclient/addTranGoods",
					async: false,
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: {
						goodsName: materialName,
						goodsWeight:weight,
						orderNo:orderNumber,
						carNo:carNo,
						goodsNo:goodsNo,
						voId:voId,
						id:id,
						driver:driver,
						phone:phone,
						uploadTime:uploadTime,
						idCard:idCard,
						planTime:planTime
					},
					success: function(data) {
						console.log(data)
						if(data.code == 100) {
							sessionStorage.removeItem("goodsNo")
							$.toptip("修改成功", 1200, 'success');
							setTimeout(function(){
								window.location.replace(document.referrer)
							},1200)				
						} else {
							$.toptip(data.content, 1200, 'error');
						}
					}
				})
			})
		})
	</script>

</html>